import {
  getList as getMesMaterialStationInventoryList,
  getTypeCodeList
} from "@/api/materialStation/mesMaterialStationInventory"

import { getUnitDictList } from "@/api/common"

export const mesMaterialStationInventoryDialog = {
  data() {
    return {
      mesMaterialStationInventoryDialogVisible: false, //表格弹框隐藏显示
      getMesMaterialStationInventoryList, // 获取弹框数据接口
      hasMesMaterialStationInventoryFooter: true, // 是否需要底部按钮默认true
      mesMaterialStationInventorySearchDialog: {
        inline: true,
        formDesc: {
          stationCode: {
            type: "input",
            layout: 8,
            label: $i18n.t("mesMaterialStationInventory.stationCode")
          },
          stationName: {
            type: "input",
            layout: 8,
            label: $i18n.t("mesMaterialStationInventory.stationName")
          }
        }
      },
      mesMaterialStationInventoryDialogColumn: [
        {
          type: "selection"
        },
        {
          type: "index",
          label: $i18n.t("common.order"),
          fixed: "left",
          width: 60
        },
        {
          prop: "stationCode",
          label: $i18n.t("mesMaterialStationInventory.stationCode"),
          minWidth: 150,
          showOverflowTooltip: true
        },
        {
          prop: "stationName",
          label: $i18n.t("mesMaterialStationInventory.stationName"),
          minWidth: 250,
          showOverflowTooltip: true
        },
        {
          prop: "volume",
          label: $i18n.t("mesMaterialStationInventory.volume"),
          minWidth: 100,
          showOverflowTooltip: true
        },
        {
          prop: "unit",
          label: $i18n.t("mesMaterialStationInventory.unit"),
          minWidth: 100,
          showOverflowTooltip: true,
          optionProp: {
            value: "value",
            label: "description"
          },
          option: async (data) => {
            const list = await getUnitDictList()
            return list.data.result
          }
        },
        {
          prop: "typeCode",
          label: $i18n.t("mesMaterialStationInventory.typeCode"),
          minWidth: 100,
          showOverflowTooltip: true,
          optionProp: {
            value: "typeCode",
            label: "typeName"
          },
          option: async (data) => {
            const list = await getTypeCodeList()
            return list.data.result
          }
        }
      ]
    }
  },
  methods: {
    // 弹框表格，双击表格，或者点击确定 返回选中数据
    getSelectMesMaterialStationInventory(data) {
      // 调试完成记得删除控制台打印
      console.log("选中数据", data)
      // 这里可以自定义返回字段信息
      // 第一个入参为当前表单绑定的对象，第二个入参为要修改的字段名，第三个入参为选中数据中相应信息
      this.$set(this.formDataDialog, "stationName", data[0].stationName)
      this.$set(this.formDataDialog, "stationCode", data[0].stationCode)
      this.$set(this.formDataDialog, "volume", data[0].volume)
      this.$set(this.formDataDialog, "unit", data[0].unit)
    }
  }
}
